(function(){
	angular.module("usergerenCtrlModule",[])
			.controller("usergerenController",["$scope","$stateParams","getDataService","$timeout",
			"$ionicLoading","$location",
				function($scope,$stateParams,getDataService,$timeout,
				$ionicLoading,$location){
				$timeout(function(){
					$scope.user = {};
					getDataService.getRequest("userId.php",
						{
							user_id:$stateParams.user_id
						},
						function(data){
							// console.log(data.data[0]);
							// console.log(data);
							if(data.code == 0){
								$scope.user = data.data[0];
								$scope.user.name = data.data[0]["u_name"];
								$scope.user.tel = data.data[0]["u_tel"];
							}else{
								$ionicLoading.show({
	                                template: data.data,
	                                duration: 1500
	                            });
							}
                        },
                        function(error){
                        	// console.log(error);
                        	$ionicLoading.show({
                                template: error,
                                duration: 1500
                            });
                        }
					)
					$scope.modifyBtn = function(){
						// console.log($scope.user);
						getDataService.getRequest("modify.php",
							{
								u_id:$stateParams.u_id,
								tel:$scope.user.tel
							},
							function(data){
								// console.log(data.data[0]);
								// console.log(data);
								if(data.code == 0){
									$ionicLoading.show({
		                                template: data.data,
		                                duration: 1500
		                            });
		                            $location.path("tab/personal");
								}else{
									$ionicLoading.show({
		                                template: data.data,
		                                duration: 1500
		                            });
								}
	                        },
	                        function(error){
	                        	// console.log(error);
	                        	$ionicLoading.show({
	                                template: error,
	                                duration: 1500
	                            });
	                        }
						)
					}
				},1000);
		}])
})();